package com.mxw.rulesengine.utils;

import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

/**
 * @Description TODO
 * @Author RingKo
 * @Date 2022/8/4 15:23
 * @Version 1.0
 */
public class RulesEngineUtil {
  private static KieContainer kieContainer;
  private static KieSession kieSession;

  private RulesEngineUtil() {
  }

  public static void setKieContainer(KieContainer kieContainer) {
    RulesEngineUtil.kieContainer = kieContainer;
    RulesEngineUtil.kieSession = kieContainer.newKieSession();
  }

  public static <T> void execute(T entity) {
    kieSession.insert(entity);
    kieSession.fireAllRules();
  }
}
